﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EpcTagLibrary
{
    public class DOD : EPC
    {
        private int m_Filter;
        private string m_Gmi;
        private long m_SerialNumber;

        public DOD(Bits bits)
            : base(bits)
        {
            Divide();
        }
       
        public DOD(byte[] bytes)
            : base(bytes)
        {
            Divide();
        }

        private void Divide()
        {
            m_Filter = (int)Common.BitsToInt(GetFieldBits(1));
            m_Gmi = Common.BitsToString(GetFieldBits(2));
            m_SerialNumber = Common.BitsToInt(GetFieldBits(3));
        }


        public int Filter
        {
            get
            {
                return m_Filter;
            }
        }

        public string Gmi
        {
            get
            {
                return m_Gmi;
            }
        }

        public long SerialNumber
        {
            get
            {
                return m_SerialNumber;
            }
        }


        public override int[] GetFieldSplits()
        {
            int[] Result = new int[3];
            Result[0] = 88;  
            Result[1] = 84;  
            Result[2] = 36;

            return Result;
        }

        public override Uri GetEPC()
        {
            StringBuilder Result = new StringBuilder();

            Result.Append("urn:epc:tag:");
            Result.Append(GetScheme());
            Result.Append(":");
            Result.Append(m_Filter);
            Result.Append(".");
            Result.Append(m_Gmi);
            Result.Append(".");
            Result.Append(m_SerialNumber);

            return new Uri(Result.ToString());
        }

        public override Uri GetTag()
        {
            StringBuilder Result = new StringBuilder();

            Result.Append("urn:epc:id:");
            Result.Append(GetSchemeName());
            Result.Append(":");
            Result.Append(m_Filter);
            Result.Append(".");
            Result.Append(m_Gmi);
            Result.Append(".");
            Result.Append(m_SerialNumber);

            return new Uri(Result.ToString());
        }

        public override string GetScheme()
        {
            return GetSchemeName() + "-" + GetTagBitLength();
        }

        public override string GetSchemeName()
        {
            return "usdod";
        }
    }
}
